$(document).ready(function() {
  
  var items = $('.carousel-item');
  var points = $('.carousel-nav button');

  
  function carousel() {
    
    var activeItem = $('.carousel-item.active');
   
    var nextItem = activeItem.next();

    
    if (!nextItem.length) {
      nextItem = items.first();
    }

    
    activeItem.removeClass('active');
    nextItem.addClass('active');
    points.eq(nextItem.index()).addClass('active').siblings().removeClass('active');
  }

  
  var timer = setInterval(carousel, 2000);


  $('.carousel').hover(function() {
    clearInterval(timer);
  }, function() {
    timer = setInterval(carousel, 3000);
  });

  
  points.click(function() {
    var index = $(this).index();
    var activeItem = $('.carousel-item.active');
    var nextItem = items.eq(index);

    if (activeItem.index() == nextItem.index()) {
      return;
    }

    activeItem.removeClass('active');
    nextItem.addClass('active');
    points.eq(nextItem.index()).addClass('active').siblings().removeClass('active');
  });
});